package com.teamelite.exmgmt;

import java.util.Timer;
import java.util.TimerTask;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.Window;
import android.widget.TextView;

public class cActivityDoTranslucent extends Activity {
	private long hr,min,sec;
	TextView tvTimer;
	
	Timer timer = new Timer();
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		// Remove title bar
		this.requestWindowFeature(Window.FEATURE_NO_TITLE);
				
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_doactivitytrans);
		tvTimer=(TextView)findViewById(R.id.tvRestTimer);
		
		this.hr=this.min=this.sec=0;
		
		timer.schedule(new tTask(), 1000, 1000);
		
	}
	
	@Override
	public boolean onTouchEvent(MotionEvent event) {
		// TODO Auto-generated method stub
		timer.cancel();
		timer.purge();
		sendBackResult();
		return true;
	}
	
	public void sendBackResult(){
		Intent sendBack = new Intent();
		sendBack.putExtra("status", 1);
		sendBack.putExtra("r_hr", this.hr);
		sendBack.putExtra("r_min", this.min);
		sendBack.putExtra("r_sec", this.sec);
		setResult(Activity.RESULT_FIRST_USER,sendBack);
		finish();
	}
	
	//tells activity to run on ui thread
	class tTask extends TimerTask {
	     @Override
	     public void run() {
	         cActivityDoTranslucent.this.runOnUiThread(new Runnable() {
	             @Override
	             public void run() {
	            	sec++;
	            	if (min>=60){ hr++; min=0; sec = 0; }
	            	if (sec>=60){ min++; sec=0; }
	            	tvTimer.setText(String.format("%02d:%02d:%02d", hr, min, sec));
	             }
	         });
	     }
	};
	
	@Override
	public void onBackPressed() {
		
	}
	
}
